package enums;

import lombok.Data;
import lombok.Getter;

@Getter
public enum ResultCodeEnum {

    SUCCESS(200, "成功"),
    FAIL(500, "失败"),
    UNAUTHORIZED(401, "未认证"),
    NOT_FOUND(404, "未找到"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    PARAM_IS_INVALID(1001, "参数无效"),
    PARAM_IS_BLANK(1002, "参数为空"),
    PARAM_TYPE_BIND_ERROR(1003, "参数类型错误"),
    PARAM_NOT_COMPLETE(1004, "参数缺失"),
    USER_NOT_LOGGED_IN(2001, "用户未登录"),
    USER_LOGIN_ERROR(2002, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(2003, "账号已被禁用"),
    USER_NOT_EXIST(2004, "用户不存在"),
    USER_HAS_EXISTED(2005, "用户已存在"),
    USER_LOGIN_SUCCESS(2006, "登录成功"),
    USER_LOGOUT_SUCCESS(2007, "登出成功"),
    USER_REGISTER_SUCCESS(2008, "注册成功"),
    USER_REGISTER_FAIL(2009, "注册失败"),
    USER_NOT_AUTHORIZED(2010, "用户未授权"),
    USER_AUTHORIZED_SUCCESS(2011, "用户授权成功"),
    USER_AUTHORIZED_FAIL(2012, "用户授权失败"),
    USER_AUTHORIZED_CANCEL_SUCCESS(2013, "用户取消授权成功"),
    USER_AUTHORIZED_CANCEL_FAIL(2014, "用户取消授权失败"),
    USER_AUTHORIZED_REFRESH_SUCCESS(2015, "用户授权刷新成功"),
    USER_AUTHORIZED_REFRESH_FAIL(2016, "用户授权刷新失败"),
    USER_AUTHORIZED_TOKEN_GET_SUCCESS(2017, "用户授权token获取成功"),
    USER_AUTHORIZED_TOKEN_GET_FAIL(2018, "用户授权token获取失败"),
    USER_AUTHORIZED_TOKEN_REFRESH_SUCCESS(2019, "用户授权token刷新成功"),
    USER_AUTHORIZED_TOKEN_REFRESH_FAIL(2020, "用户授权token刷新失败"),
    USER_AUTHORIZED_TOKEN_INVALID(2021, "用户授权token无效"),
    USER_AUTHORIZED_TOKEN_EXPIRED(2022, "用户授权token过期"),
    USER_AUTHORIZED_TOKEN_ERROR(2023, "用户授权token错误"),
    USER_AUTHORIZED_TOKEN_NOT_EXIST(2024, "用户授权token不存在");

    private Integer code;
    private String desc;

    ResultCodeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public static ResultCodeEnum getByCode(Integer code) {
        for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
            if (resultCodeEnum.getCode().equals(code)) {
                return resultCodeEnum;
            }
        }
        return null;
    }

}
